/*
 * @Description: 添加拨打电话号码功能
 * @Version: V1.0.0
 * @Author: 黄鑫
 * @Date: 2025-07-30
 * @LastEditors: 黄鑫
 * @LastEditTime: 2025-08-06
 * @FilePath: TelPhoneView.dart
 * @Remarks: 
 */
import 'package:flutter/material.dart';
import 'package:hx_base/pages/BaseToast.dart';
import 'package:url_launcher/url_launcher.dart';

class TelPhoneView extends StatelessWidget {
  // 电话号码
  String phone;

  EdgeInsets? margin;

  EdgeInsets? padding;

  BoxDecoration? boxDecoration;

  TextStyle? textStyle;

  TelPhoneView(
      {super.key,
      required this.phone,
      this.margin,
      this.padding,
      this.boxDecoration,
      this.textStyle});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () async {
        if (phone.isEmpty) {
          BaseToast.showError("无电话号码");
          return;
        }
        final url = Uri(scheme: "tel", path: phone);
        if (await canLaunchUrl(url)) {
          await launchUrl(url);
        }
      },
      child: Container(
        margin: margin,
        padding: padding,
        decoration: boxDecoration ??
            BoxDecoration(
              color: Colors.white,
            ),
        child: Text(phone, style: textStyle),
      ),
    );
  }
}
